package com.ruoyi.sl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sl.domain.SlBreed;
import com.ruoyi.sl.service.ISlBreedService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 品类Controller
 * 
 * @author admin
 * @date 2024-06-03
 */
@RestController
@RequestMapping("/sl/breed")
public class SlBreedController extends BaseController
{
    @Autowired
    private ISlBreedService slBreedService;

    /**
     * 查询品类列表
     */
    @PreAuthorize("@ss.hasPermi('sl:breed:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlBreed slBreed)
    {
        startPage();
        List<SlBreed> list = slBreedService.selectSlBreedList(slBreed);
        return getDataTable(list);
    }

    /**
     * 获取所有颜色
     */
    @GetMapping(value = "/all")
    public AjaxResult getAllList()
    {
        return success(slBreedService.selectBreedAll());
    }

    /**
     * 导出品类列表
     */
    @PreAuthorize("@ss.hasPermi('sl:breed:export')")
    @Log(title = "品类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlBreed slBreed)
    {
        List<SlBreed> list = slBreedService.selectSlBreedList(slBreed);
        ExcelUtil<SlBreed> util = new ExcelUtil<SlBreed>(SlBreed.class);
        util.exportExcel(response, list, "品类数据");
    }

    /**
     * 获取品类详细信息
     */
    @PreAuthorize("@ss.hasPermi('sl:breed:query')")
    @GetMapping(value = "/{breedId}")
    public AjaxResult getInfo(@PathVariable("breedId") Long breedId)
    {
        return success(slBreedService.selectSlBreedByBreedId(breedId));
    }

    /**
     * 新增品类
     */
    @PreAuthorize("@ss.hasPermi('sl:breed:add')")
    @Log(title = "品类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlBreed slBreed)
    {
        slBreed.setCreateBy(getUsername());
        return toAjax(slBreedService.insertSlBreed(slBreed));
    }

    /**
     * 修改品类
     */
    @PreAuthorize("@ss.hasPermi('sl:breed:edit')")
    @Log(title = "品类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlBreed slBreed)
    {
        slBreed.setUpdateBy(getUsername());
        return toAjax(slBreedService.updateSlBreed(slBreed));
    }

    /**
     * 删除品类
     */
    @PreAuthorize("@ss.hasPermi('sl:breed:remove')")
    @Log(title = "品类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{breedIds}")
    public AjaxResult remove(@PathVariable Long[] breedIds)
    {
        return toAjax(slBreedService.deleteSlBreedByBreedIds(breedIds));
    }
}
